﻿using System;

namespace Bouyei.SqlProvider
{
    using Expression;
    using Extensions;
    using Structure;

    public class Provider
    {
        public Provider()
        {
        }

        class instance
        {
            internal static Provider provider = new Provider();
            static instance()
            { } 
        }

        public static Provider Singleton
        {
           get { return instance.provider; }
        }

        public Select Select(params string[] columns)
        {
           Select _select = new Select(columns);
            _select.SqlString = _select.ToString();
            return _select;
        }

        public Select<T> Select<T>() where T : class
        {
            Select<T> _select = new Select<T>();
            _select.SqlString = _select.ToString();
            return _select;
        }

        public Insert InsertInto(string tableName,string[] Columns, string[,] Values)
        {
            Insert insert = new Insert(tableName, Columns, Values);
            insert.SqlString = insert.ToString();

            return insert;
        }

        public Insert<T>InsertInto<T>(string tableName,T Value) where T:class
        {
            Insert<T> insert = new Insert<T>(Value);
            insert.SqlString= insert.ToString();

            return insert;
        }

        public Insert<T> InsertInto<T>(string tableName,T[] Values) where T:class
        {
            Insert<T> insert = new Insert<T>(Values);
            insert.SqlString = insert.ToString();

            return insert;
        }

        public Update Update(string tableName)
        {
            Update up = new Update(tableName);
            up.SqlString = up.ToString();
            return up;
        }

        public Update<T> Update<T>()
        {
            Update<T> up = new Expression.Update<T>();
            up.SqlString = up.ToString();

            return up;
        }

        public Delete<T> Delete<T>() where T : class
        {
            Delete<T> delete = new Expression.Delete<T>();
            delete.SqlString = delete.ToString();

            return delete;
        }

        public Delete Delete()
        {
            Delete delete = new Expression.Delete();
            delete.SqlString = delete.ToString();

            return delete;
        }
    }

    public class Provider<T> where T : class
    {
        public Provider()
        {
        }

        public Select Select(params string[] columns)
        {
            Select _select = new Select(columns);
            _select.SqlString = _select.ToString();
            return _select;
        }
    }
}
